package com.cloud.base.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class GetBeanUtils implements ApplicationContextAware {
    //将BeanFactory容器以成员变量保存
    private static ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
            context = applicationContext;
    }

    //获取ApplicationContext的测试方法
    public ApplicationContext getContext() {
        return context;
    }

    public static Object getBean(String name){
        return context.getBean(name);
    }
}
